package com.lujianfei.productprice.base;

import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;

import com.lujianfei.productprice.R;
import com.lujianfei.productprice.utils.ResUtils;
import com.lujianfei.productprice.utils.StatusBarUtils;
import com.lujianfei.productprice.widget.CustomTitleBar;

import androidx.annotation.LayoutRes;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public class BaseActivity extends AppCompatActivity implements IBaseActivity{

    private CustomTitleBar customTitleBar;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        StatusBarUtils.with(this).setColor(ResUtils.getColor(R.color.colorPrimary)).init();
        super.onCreate(savedInstanceState);
    }
    @Override
    public void setContentView(@LayoutRes int layoutResID) {
        super.setContentView(layoutResID);
        customTitleBar = findViewById(getTitleBarResId());
        if (null == customTitleBar){
            return;
        }
        customTitleBar.setOnLeftImgClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onTitleLeftImageClick();
            }
        });
        customTitleBar.setOnLeftTxtClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
            }
        });
        customTitleBar.setOnRightImgClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onTitleRightImageClick();
            }
        });
        customTitleBar.setOnRightTxtClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
            }
        });
    }

    protected int getTitleBarResId(){
        return 0;
    }

    @Override
    public void hideTitleLeft() {
        if (null!=customTitleBar){
            customTitleBar.hideTitleLeft();

        }
    }

    @Override
    public void showTitleLeft() {
        if (null!=customTitleBar){
            customTitleBar.showTitleLeft();
        }
    }

    @Override
    public void setTitleLeftText(String leftText) {
        if (null!=customTitleBar){
            customTitleBar.setTitleLeftText(leftText);
        }
    }

    @Override
    public void showTitleLeftText() {
        if (null!=customTitleBar){
            customTitleBar.showTitleLeftText();
        }
    }

    @Override
    public void hideTitleLeftText() {
        if (null!=customTitleBar){
            customTitleBar.hideTitleLeftText();
        }
    }

    @Override
    public void setTitleLeftImage(int resImg) {
        if (null!=customTitleBar){
            customTitleBar.setTitleLeftImage(resImg);
        }
    }

    @Override
    public void showTitleLeftImage() {
        if (null!=customTitleBar){
            customTitleBar.showTitleLeftImage();
        }
    }

    @Override
    public void hideTitleLeftImage() {
        if (null!=customTitleBar){
            customTitleBar.hideTitleLeftImage();
        }
    }

    @Override
    public void onTitleLeftImageClick() {
            finish();
    }

    @Override
    public void hideTitleRight() {
        if (null!=customTitleBar){
            customTitleBar.hideTitleRight();
        }
    }

    @Override
    public void showTitleRight() {
        if (null!=customTitleBar){
            customTitleBar.showTitleRight();
        }
    }

    @Override
    public void setTitleRightText(String rightText) {
        if (null!=customTitleBar){
            customTitleBar.setTitleRightText(rightText);
        }
    }

    @Override
    public void showTitleRightText() {
        if (null!=customTitleBar){
            customTitleBar.showTitleRightText();
        }
    }

    @Override
    public void hideTitleRightText() {
        if (null!=customTitleBar){
            customTitleBar.hideTitleRightText();
        }
    }

    @Override
    public void setTitleRightImage(int resImg) {
        if (null!=customTitleBar){
            customTitleBar.setTitleRightImage(resImg);
        }
    }

    @Override
    public void showTitleRightImage() {
        if (null!=customTitleBar){
            customTitleBar.showTitleRightImage();
        }
    }

    @Override
    public void hideTitleRightImage() {
        if (null!=customTitleBar){
            customTitleBar.hideTitleRightImage();
        }
    }

    @Override
    public void onTitleRightImageClick() {

    }

    @Override
    public void setTitleBackgroundColor(int color) {
        if (null!=customTitleBar){
            customTitleBar.setBackgroundColor(color);
        }
    }

    @Override
    public void setTitleMiddleText(String middleText) {
        if (null!=customTitleBar){
            customTitleBar.setTitleMiddleText(middleText);
        }
    }

    @Override
    public void setTitleMiddleText(String middleText, boolean showMiddle) {
        if (null!=customTitleBar){
            customTitleBar.setTitleMiddleText(middleText,showMiddle);
        }
    }

    @Override
    protected void onResume() {
        /**
         * 设置为竖屏
         */
        if(getRequestedOrientation()!=ActivityInfo.SCREEN_ORIENTATION_PORTRAIT){
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }
        super.onResume();
    }
}
